package com.quick.job;

import com.quick.mapper.ReconJobMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * @author wangxin86
 * @title: DefaultJobSchedulerRegistrar
 * @description: TODO
 * @date 2019/7/29 15:24
 */
@Component
public class DefaultJobSchedulerRegistrar implements JobSchedulerRegistrar{
    @Resource
    private ReconJobMapper reconJobMapper;

    /**
     * @return java.util.List<com.quick.job.JobScheduleConfig>
     * @author wangxin86
     * @description: TODO
     * @date 2019/7/29
     */
    @Override
    public List<JobScheduleConfig> getScheduleConfigs() {
        List<ReconJob> reconJobs = reconJobMapper.enableJobRuleList();
        if (null == reconJobs || reconJobs.size() == 0) {
            return null;
        }
        List<JobScheduleConfig> configList = new LinkedList<>();
        for (ReconJob item : reconJobs) {
            JobScheduleConfig config = new JobScheduleConfig();
            config.setJobName(item.getJobName());
            config.setScheduleCron(item.getSchedule());
            config.setJobParameter(String.valueOf(item.getId()));
            config.setJobExecutorName(item.getHandlerName());
            configList.add(config);
        }
        return configList;
    }
}
